package jdbc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OracleDriver {

	public static List<Map<String, Object>> executeQuery(String sql) {
		List<Map<String, Object>> list = new ArrayList<>();
		int selectI = sql.indexOf("select");
		int fromI = sql.indexOf("from");
		int whereI = sql.indexOf("where");
		String selectPart = sql.substring(selectI+"select".length(), fromI);
		String fromPart = sql.substring(fromI + "from".length(), whereI);
		String wherePart = sql.substring(whereI + "where".length());
		if (fromPart.indexOf("user") != -1) {
			Map<String, Object> map = new HashMap<String, Object>();
			if (selectPart.indexOf("id") != -1) {
				map.put("id", "001");
			}
			if (selectPart.indexOf("email") != -1) {
				map.put("email", "132@139.com");
			}
			if (selectPart.indexOf("age") != -1) {
				map.put("age", 29);
			}
			if (selectPart.indexOf("address") != -1) {
				map.put("address", "guangdong");
			}
			list.add(map);
		}
		return list;
	}
}
